package com.c4.service.impl;

import com.c4.dao.deviceStatusDao;
import com.c4.domain.PageBean;
import com.c4.domain.deviceStatus;
import com.c4.service.IdeviceStatusService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class deviceStatusImpl implements IdeviceStatusService {
    @Autowired
    private deviceStatusDao deviceStatusDao;

    //设备分页查询
    @Override
    public PageBean<deviceStatus> list(Integer pageNum, Integer pageSize) {
        //创建PageBean对象
        PageBean<deviceStatus> pd = new PageBean<>();
        //开启分页查询
        PageHelper.startPage(pageNum,pageSize);

        List<deviceStatus> ds = deviceStatusDao.list();
        Page<deviceStatus> d = (Page<deviceStatus>) ds;
        pd.setTotal(d.getTotal());
        pd.setItems(d.getResult());
        return pd;
    }
    //根据id找设备
    @Override
    public deviceStatus detail(Integer id) {
        deviceStatus d = deviceStatusDao.detail(id);
        return d;
    }
    //设备全部显示
    @Override
    public List<deviceStatus> listAll() {
        return deviceStatusDao.listAll();
    }
    //添加设备
    @Override
    public void add(deviceStatus deviceStatus) {
        deviceStatusDao.add(deviceStatus);
    }
    //删除设备
    @Override
    public void delete(Integer id) {
        deviceStatusDao.delete(id);
    }
    //故障设备分页展示
    @Override
    public PageBean<deviceStatus> listWarn(Integer pageNum, Integer pageSize) {
        //创建PageBean对象
        PageBean<deviceStatus> pd = new PageBean<>();
        //开启分页查询
        PageHelper.startPage(pageNum,pageSize);

        List<deviceStatus> ds = deviceStatusDao.listWarn();
        Page<deviceStatus> d = (Page<deviceStatus>) ds;
        pd.setTotal(d.getTotal());
        pd.setItems(d.getResult());
        return pd;
    }
    //正常设备显示
    @Override
    public List<deviceStatus> listAllNormal() {
        return deviceStatusDao.listAllNormal();
    }
    //修改设备故障状态
    @Override
    public void warnUpdate(deviceStatus deviceStatus) {
        deviceStatus.setWarnTime(LocalDateTime.now());
        deviceStatusDao.warnUpdate(deviceStatus);
    }
    //设备故障已解决分页显示
    @Override
    public PageBean<deviceStatus> listStra(Integer pageNum, Integer pageSize) {
        //创建PageBean对象
        PageBean<deviceStatus> pd = new PageBean<>();
        //开启分页查询
        PageHelper.startPage(pageNum,pageSize);

        List<deviceStatus> ds = deviceStatusDao.listStra();
        Page<deviceStatus> d = (Page<deviceStatus>) ds;
        pd.setTotal(d.getTotal());
        pd.setItems(d.getResult());
        return pd;
    }
    //故障设备处理策略
    @Override
    public void straUpdate(deviceStatus deviceStatus) {
        deviceStatus.setStraTime(LocalDateTime.now());
        deviceStatusDao.straUpdate(deviceStatus);
    }

}
